package com.pj.utils.wx;

import com.pj.utils.SspClientBrdUtil;
import me.chanjar.weixin.open.api.WxOpenConfigStorage;
import me.chanjar.weixin.open.api.WxOpenService;
import me.chanjar.weixin.open.api.impl.WxOpenInMemoryConfigStorage;
import me.chanjar.weixin.open.api.impl.WxOpenServiceImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class WxOpenConfiguration {

    /**
     * 微信客户端配置存储
     */
    @Bean
    public WxOpenConfigStorage wxOpenConfigStorage() {
        WxOpenInMemoryConfigStorage wxOpenInMemoryConfigStorage = new WxOpenInMemoryConfigStorage();
        // 设置微信公众号appId
        wxOpenInMemoryConfigStorage.setComponentAppId(SspClientBrdUtil.appid);
        // 设置微信公众号appSecret
        wxOpenInMemoryConfigStorage.setComponentAppSecret(SspClientBrdUtil.appsecret);
        // 设置微信公众号的token
//        wxOpenInMemoryConfigStorage.setComponentToken(wxMpProperties.getToken());
        // 设置微信公众号的EncodingAESKey
//        wxOpenInMemoryConfigStorage.setComponentAesKey(wxMpProperties.getAesKey());
        return wxOpenInMemoryConfigStorage;
    }

    /**
     * WxMpService多个实现类 声明一个实例
     */
    @Bean
    public WxOpenService wxOpenService() {

        WxOpenService wxOpenService = new WxOpenServiceImpl();
        wxOpenService.setWxOpenConfigStorage(wxOpenConfigStorage());
        return wxOpenService;
    }
}